package com.fottas.adware.portal.service.impl;

import com.fottas.adware.mapper.RmsPriviledgePromotionMapper;
import com.fottas.adware.mapper.TmsTaskCategoryMapper;
import com.fottas.adware.mapper.TmsTaskMapper;
import com.fottas.adware.model.*;
import com.fottas.adware.portal.dao.HomeDao;
import com.fottas.adware.portal.domain.HomeContentResult;
import com.fottas.adware.portal.service.HomeService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 首页内容管理Service实现类
 */
@Service
public class HomeServiceImpl implements HomeService {
    @Autowired
    private HomeDao homeDao;
    @Autowired
    private TmsTaskMapper taskMapper;
    @Autowired
    private TmsTaskCategoryMapper taskCategoryMapper;
    @Autowired
    private RmsPriviledgePromotionMapper priviledgePromotionMapper;

    @Override
    public HomeContentResult content() {
        HomeContentResult result = new HomeContentResult();
        result.setNewTaskList(homeDao.getNewTaskList(0,10));
        result.setHotTaskList(homeDao.getHotTaskList(0,10));
        result.setPriviledgePromotionList(getPriviledgePromotionList());
        result.setTaskCategoryList(getTaskCateList());
        return result;
    }

    public List<RmsPriviledgePromotion> getPriviledgePromotionList(){
        RmsPriviledgePromotionExample example = new RmsPriviledgePromotionExample();
        example.createCriteria();
        return priviledgePromotionMapper.selectByExample(example);
    }

    /**
     * 获取商品类别
     */
    public List<TmsTaskCategory> getTaskCateList() {
        TmsTaskCategoryExample example = new TmsTaskCategoryExample();
        example.createCriteria()
                .andShowStatusEqualTo(1)
                .andParendIdEqualTo(0L);
        return taskCategoryMapper.selectByExample(example);
    }

    @Override
    public List<TmsTask> recommendTaskList(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        TmsTaskExample example = new TmsTaskExample();
        example.createCriteria()
                .andDeleteStatusEqualTo(0)
                .andPublishStatusEqualTo(1)
                .andRecommandStatusEqualTo(1);
        return taskMapper.selectByExample(example);
    }
}
